import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;

import CustomSprite;
import Button;
import Images;
import PopUpText;

class CharityMenuEvent extends Event{
public var Number:String;
	public function new(customEventString:String,inNumber:String){
	Number = inNumber;
	super(customEventString, true, false);

    }
}

class CharityMenu extends GenericMenu
{
public var SmallCharity:Button;
public var MediumCharity:Button;
public var LargeCharity:Button;
public var Give:Button;
public var Description:TextField;
private var currentDescription:String;
public var OkPopUpText : PopUpText;
public var popUpState : String;
public var  buttonSprite : Sprite;
public var  background : Sprite;

public function new(inBackground:BitmapData) {
  super(inBackground);
     this.graphics.clear();
    this.removeChild(BackButton);
    background = new Sprite();
     background.graphics.clear();
      background.graphics.beginFill(0xFFFFFF);
      //Grid.graphics.drawRect(0, 0,620-150,472);
      background.graphics.drawRect(0,0,640,472);
      background.graphics.endFill();
      background.alpha =0.5;
      buttonSprite = new Sprite();
      buttonSprite.graphics.beginFill(0xFFFFFF);
      //Grid.graphics.drawRect(0, 0,620-150,472);
      buttonSprite.graphics.drawRect(0,0,640,Constants.flashHeight-20);
      buttonSprite.graphics.endFill();
      buttonSprite.addChild(BackButton);
  Description = new TextField();
  currentDescription = "Here is where you make Donations";
  Description.htmlText= "<font color='#000000' size='16'>"+currentDescription+"</font>";
  Description.wordWrap = true;

  buttonSprite.addChild(Description);
  SmallCharity = new Button(250,50,"Buy A Small Charity",0xFFFFFF,0x000000);
  SmallCharity.x = 10;
  SmallCharity.y = 10;
  SmallCharity.buttonMode = true;
  buttonSprite.addChild(SmallCharity);
  
  SmallCharity.addEventListener(MouseEvent.MOUSE_OVER, onSmallCharityOver);
  SmallCharity.addEventListener(MouseEvent.CLICK, onSmallCharityClick);
  SmallCharity.addEventListener(MouseEvent.MOUSE_OUT, onSmallCharityOut);

MediumCharity = new Button(250,50,"Buy A Medium Charity",0xFFFFFF,0x000000);
  MediumCharity.x = 10;
  MediumCharity.y = 60;
  MediumCharity.buttonMode = true;
  buttonSprite.addChild(MediumCharity);
  
  MediumCharity.addEventListener(MouseEvent.MOUSE_OVER, onMediumCharityOver);
  MediumCharity.addEventListener(MouseEvent.CLICK, onMediumCharityClick);
  MediumCharity.addEventListener(MouseEvent.MOUSE_OUT, onMediumCharityOut);

  LargeCharity = new Button(250,50,"Buy A Large Charity",0xFFFFFF,0x000000);
  LargeCharity.x = 10;
  LargeCharity.y = 110;
  LargeCharity.buttonMode = true;
  buttonSprite.addChild(LargeCharity);
  
  LargeCharity.addEventListener(MouseEvent.MOUSE_OVER, onLargeCharityOver);
  LargeCharity.addEventListener(MouseEvent.CLICK, onLargeCharityClick);
  LargeCharity.addEventListener(MouseEvent.MOUSE_OUT, onLargeCharityOut);

  Give = new Button(250,50,"Donate",0xFFFFFF,0x000000);
  Give.x = 10;
  Give.y = 160;
  Give.buttonMode = true;
  buttonSprite.addChild(Give);
  
  Give.addEventListener(MouseEvent.MOUSE_OVER, onGiveOver);
  Give.addEventListener(MouseEvent.CLICK, onGiveClick);
  Give.addEventListener(MouseEvent.MOUSE_OUT, onGiveOut);
  this.addEventListener("PopUpTextEvent",onPopUpTextEvent);

  OkPopUpText = new PopUpText(inBackground.clone(),"Enter Amount To Donate");

  var myFormat:TextFormat = new TextFormat();
  //myFormat.size = 15;
  Description.autoSize = TextFieldAutoSize.CENTER;
  //Turning off for now
  Description.x = 405;
  Description.y = (height-32) / 2 + 75;
  Description.width=230;
  
  
  Description.selectable = false;
  Description.mouseEnabled = false;
  addChild(background);
  addChild(buttonSprite);

  }
private function onSmallCharityClick(event:MouseEvent){
      dispatchEvent(new CharityMenuEvent("ignoreKeyPress","-1"));
    popUpState = "SmallCharity";
    this.addChild(OkPopUpText);
   OkPopUpText.text.htmlText = "Enter Number of Small Charities to Buy";
    OkPopUpText.Load();
}
private function onSmallCharityOver(event:MouseEvent) {
 Description.htmlText= "<font color='#000000' size='16'>"+"Small Charity Costs $10,000 and helps 20 people per week. Shortkey 4"+"</font>";
}

private function onSmallCharityOut(event:MouseEvent) {
 Description.htmlText= "<font color='#000000' size='16'>"+currentDescription+"</font>";
}
private function onMediumCharityClick(event:MouseEvent){
      dispatchEvent(new CharityMenuEvent("ignoreKeyPress","-1"));
    popUpState = "MediumCharity";
    this.addChild(OkPopUpText);
    OkPopUpText.text.htmlText = "Enter Number of Medium Charities to Buy";
    OkPopUpText.Load();
}
private function onMediumCharityOver(event:MouseEvent) {
 Description.htmlText= "<font color='#000000' size='16'>"+"Medium Charity Costs $100,000 and helps 400 people per week. Shortkey 5"+"</font>";
}

private function onMediumCharityOut(event:MouseEvent) {
 Description.htmlText= "<font color='#000000' size='16'>"+currentDescription+"</font>";
}
private function onLargeCharityClick(event:MouseEvent){
    dispatchEvent(new CharityMenuEvent("ignoreKeyPress","-1"));
    popUpState = "LargeCharity";
    this.addChild(OkPopUpText);
    OkPopUpText.text.htmlText = "Enter Number of Large Charities to Buy";
    OkPopUpText.Load();
  //dispatchEvent(new CharityMenuEvent("LargeCharity","-1"));
}
private function onLargeCharityOver(event:MouseEvent) {
 Description.htmlText= "<font color='#000000' size='16'>"+"Medium Charity Costs $1,000,000 and helps 8,000 people per week. Shortkey 6"+"</font>";
}

private function onLargeCharityOut(event:MouseEvent) {
 Description.htmlText= "<font color='#000000' size='16'>"+currentDescription+"</font>";
}

private function onGiveClick(event:MouseEvent){
    dispatchEvent(new CharityMenuEvent("ignoreKeyPress","-1"));
    popUpState = "Donate";
    this.addChild(OkPopUpText);
    OkPopUpText.Load();
}
private function onGiveOver(event:MouseEvent) {
 Description.htmlText= "<font color='#000000' size='16'>"+"Donate Money. Every $100 helps 1 person. Excess Change is burned.  Shortkey D"+"</font>";
}

private function onGiveOut(event:MouseEvent) {
 Description.htmlText= "<font color='#000000' size='16'>"+currentDescription+"</font>";
}

private function onPopUpTextEvent(event:PopUpTextEvent){
  this.removeChild(OkPopUpText);
  if(popUpState == "Donate")
  {dispatchEvent(new CharityMenuEvent("Give",event.Number));}
else if(popUpState == "SmallCharity")
  {dispatchEvent(new CharityMenuEvent("SmallCharity",event.Number));}
else if(popUpState == "MediumCharity")
  {dispatchEvent(new CharityMenuEvent("MediumCharity",event.Number));}
  else if(popUpState == "LargeCharity")
  {dispatchEvent(new CharityMenuEvent("LargeCharity",event.Number));}
}

}	